app.controller('AreaListCtrl', function($scope, ajax, $stateParams, toaster, $modal) {
    var deleter = new Req.DELETE({ resource: $scope.resource });
    var updater = new Req.PUT({ resource: $scope.resource });

    $scope.city = $stateParams.city;
    $scope.name = $stateParams.name;

    $scope.reload = function() {
        ajax.call(new Req.GET({
            resource: 'city/rt/serviceArea/' + $stateParams.city + '/list'
        })).then(function(result) {
            $scope.areaList = result.result;
        }, function() { });
    };
    $scope.reload();

    // 新增、更新
    $scope.write = function(size, current_data, submit_type) {
        $scope.current_data = angular.copy(current_data);
        var modalInstance = $modal.open({
            templateUrl: 'template/rent/city/areaUpdate.html?v=3d80b2c038',
            controller: 'AreaModalCtrl',
            size: size,
            resolve: {
                param: function() {
                    return {
                        "data": $scope.current_data,
                        "type": submit_type
                    };
                }
            }
        });

        modalInstance.result.then(function(param) {
            if (param.type == 'update') {
                updater.fields = param.data;
                updater.id = param.data.id;
                updater.resource = 'city/rt/serviceArea/update';
                $scope.page.mod(updater, $scope.reload);
            }
        });
    };

    //删除
    $scope.del = function(size, current_data, submit_type) {
		var modalInstance = $scope.delModal(size, current_data, submit_type);
        modalInstance.result.then(function(param) {
            if (param.type == 'delete') {
                deleter.id = param.data.id;
                deleter.resource = 'city/rt/serviceArea/' + deleter.id + '/delete';
                $scope.page.del(deleter, $scope.reload);
            }
        });
    };
});
